<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *留言记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	$id=$merchid;
	if($id){
		$item=pdo_get('jy_51job_merch',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['images']=json_decode($item['images'],true);
		$item['tui_ids']=json_decode($item['tui_ids'],true);
		$item['lat_lng']=json_decode($item['lat_lng'],true);
	}else{
		$item=array();
	}
	$item['pcd']=$item['pcd']?json_decode($item['pcd'],true):array('city'=>'');
	$item['upass']='';
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'企业名称','name'=>'title','help'=>''),
					array('type'=>'image','title'=>'企业LOGO','name'=>'logo','help'=>''),
					array('type'=>'text','title'=>'企业描述','name'=>'desc','help'=>''),
					array('type'=>'radio','title'=>'企业性质','name'=>'type','options'=>'merch_type'),
					array('type'=>'radio','title'=>'企业规模','name'=>'teamtype','options'=>'teamtype'),
					array('type'=>'checkbox','title'=>'所属行业','name'=>'cids','options'=>'groups'),
					array('type'=>'richtext','title'=>'企业详情','name'=>'content','help'=>''),
					array('type'=>'pcd','title'=>'城市','name'=>'pcd'),
					array('type'=>'string','title'=>'地址','name'=>'address'),
					array('type'=>'lat_lng','title'=>'坐标','name'=>'lat_lng'),
				    array('name'=>'mid','title'=>'发布人','type'=>'choose','action'=>'core/member.get_member/'),
					array('name'=>'uname','must'=>true,'title'=>'账户名','type'=>'string'),
					array('name'=>'upass','title'=>'账户密码','type'=>'string'),
					array('name'=>'name','title'=>'联系人姓名','type'=>'string'),
					array('name'=>'mobile','title'=>'联系人电话','type'=>'string'),
					array('type'=>'string','title'=>'浏览量','name'=>'looks','help'=>''),
					array('type'=>'switch','title'=>'是否启用','name'=>'status','help'=>'设置是否启用'),
					array('name'=>'paixu','title'=>'排序','type'=>'string'),
				)
			),
			array(
				'title'=>'企业资质',
				'list'=>array(
					array('type'=>'string','title'=>'开户银行','name'=>'banktitle','help'=>''),
					array('type'=>'string','title'=>'银行卡号','name'=>'banksn','help'=>''),
					array('type'=>'image','title'=>'营业执照','name'=>'codeimg','help'=>''),
					array('type'=>'string','title'=>'执照编号','name'=>'codesn','help'=>''),
					array('type'=>'string','title'=>'法人姓名','name'=>'codename','help'=>''),
					array('type'=>'image','title'=>'法人身份证正面','name'=>'codeimg1','help'=>''),
					array('type'=>'image','title'=>'法人身份证背面','name'=>'codeimg2','help'=>''),
				)
			),
		)
	);
	if($_SESSION['os']=='windows'){
		$return['htmls']=$htmls;
	}
	$groups=pdo_getall('jy_51job_merch_group',array('uniacid'=>$_SESSION['uniacid']));
	$return['groups']=array();
	foreach($groups as $gv){
		$return['groups'][$gv['id']]=$gv['title'];
	}
	$return['merch_type']=$this->merch_type;
	$return['teamtype']=$this->teamtype;
	set_html('title','企业注册');
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['pcd']['city']){
		exi('城市不能为空！','error');
	}
	if(!$postdata['pcd']['district']){
		exi('区域不能为空！','error');
	}
	if(!$postdata['address']){
		exi('地址不能为空！','error');
	}
	if(!$postdata['name']){
			exi('联系人姓名不能为空！','error');
	}
	if(!$postdata['title'] || !$postdata['mobile'] || !$postdata['codeimg'] || !$postdata['codesn']){
		exi('请先完善联系电话，企业名称，营业执照，执照编号！','error');
	}
	if((strlen($postdata['mobile'])!=11 && strlen($postdata['mobile'])!=18) || $postdata['mobile'][0]!='1' || !is_numeric($postdata['mobile'])){
		exi('手机号码格式错误，请输入11/18位，1开头的手机号！！','error');
	}
	if(empty($postdata['lat_lng'])){
			//exi('请选择坐标！','error');
	}
	if($postdata['pcd']){
		if($postdata['pcd']['city']){
			if($postdata['pcd']['city']=='北京市' || $postdata['pcd']['city']=='上海市' || $postdata['pcd']['city']=='天津市'){
				$address=$postdata['pcd']['city'].' 市辖区';
			}else{
				$address=$postdata['pcd']['province'].' '.$postdata['pcd']['city'];
			}
			$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
		}
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'logo'=>trim($postdata['logo']),
		'desc'=>trim($postdata['desc']),
		'mid'=>intval($postdata['mid']),
		'content'=>trim($postdata['content']),
		'uname'=>trim($postdata['uname']),
		'name'=>trim($postdata['name']),
		'mobile'=>trim($postdata['mobile']),
		'address'=>trim($postdata['address']),
		'codesn'=>trim($postdata['codesn']),
		'codeimg'=>trim($postdata['codeimg']),
		'codeimg1'=>trim($postdata['codeimg1']),
		'codeimg2'=>trim($postdata['codeimg2']),
		'codename'=>trim($postdata['codename']),
		'banktitle'=>trim($postdata['banktitle']),
		'banksn'=>trim($postdata['banksn']),
		'status'=>intval($postdata['status']),
		'type'=>intval($postdata['type']),
		'pcd'=>ijson_encode($postdata['pcd']),
		'city'=>trim($postdata['pcd']['city']),
		'district'=>trim($postdata['pcd']['district']),
		'code'=>$code,
		'looks'=>intval($postdata['looks']),
		'paixu'=>intval($postdata['paixu']),
		'teamtype'=>intval($postdata['teamtype']),
		'cids'=>trim($postdata['cids']),
		'updatetime'=>time(),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_51job_merch',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$uppcd=array(
			'province'=>$postdata['pcd']['province'],
			'city'=>$postdata['pcd']['city'],
			'district'=>$postdata['pcd']['district'],
		);
		pdo_update('jy_51job_job',$uppcd,array('merchid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['status']=1;
		$data['createtime']=time();
		pdo_insert('jy_51job_merch',$data);
		$merchid=pdo_insertid();
		pdo_update('jy_51job_merch_account',array('merchid'=>$merchid),array('id'=>$_SESSION['userid'],'uniacid'=>$_SESSION['uniacid']));
	}
	if($_SESSION['os']=='windows'){
		exi('操作成功！','','goback');
	}else{
		exi('操作成功！','','/merch.index/');
	}
}
